package com.common.app.base

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.common.app.R
import com.common.app.databinding.ActivityContentBinding
import com.common.app.helper.RouterHelper
import com.common.base.app.activity.BaseVBActivity
import com.common.base.utils.AppUtils

/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2022/8/19
 * <p>
 * 描述：
 * <p>
 * 修订历史：
 */
class ContentActivity : BaseVBActivity<ActivityContentBinding>() {

    companion object {
        fun getIntent(context: Context?, path: String, data: Bundle?= null): Intent {
            val intent = Intent(context, ContentActivity::class.java)
            intent.putExtra("path", path)
            if (data != null){
                intent.putExtras(data)
            }
            return intent
        }
    }

    override fun getViewBinding() = ActivityContentBinding.inflate(layoutInflater)

    override fun initViews() {
        super.initViews()
        val path = intent.getStringExtra("path")
        path?.let {
            val fragment = RouterHelper.obtainARouterFragment(path)
            if (fragment != null) {
                intent.extras?.let{
                    fragment.arguments = it
                }
                AppUtils.commitFragment(supportFragmentManager, fragment, R.id.contentLayout)
            } else {
                finish()
            }
        }
    }

}